/**
*      author: Y_Yao
*      created: 2025-04-03 09:19:08
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 7;
int n,m,k;
int cntn,cntm;
map<pair<int,int>,bool> mp;
vector<pair<int,int>> ans;
int res[N];

struct node
{
    int op,a,x;
};

node a[N];

void check(int op,int a,int x)
{
    if(mp.count({op,a}))
    {
        return;
    }
    mp[{op,a}] = true;
    if(op == 1)
    {
        res[x] += m - cntm;
        cntn++;
    }
    else
    {
        res[x] += n - cntn;
        cntm++;
    }
}

void solve()
{
    cin >> n >> m >> k;
    for(int i = 1;i <= k;i++)
    {
        cin >> a[i].op >> a[i].a >> a[i].x;
    }
    for(int i = k;i >= 1;i--)
    {
        check(a[i].op,a[i].a,a[i].x);
    }
    for(int i = 1;i <= n;i++)
    {
        check(1,i,0);
    }
    for(int i = 0;i < N;i++)
    {
        if(res[i])
        {
            ans.push_back({i,res[i]});
        }
    }
    cout << ans.size() << endl;
    for(auto& e : ans)
    {
        cout << e.first << " " << e.second << endl;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}